using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace RestNews.Data.Models.Mapping
{
    public class NewsItemMap : EntityTypeConfiguration<NewsItem>
    {
        public NewsItemMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Title)
                .IsRequired()
                .HasMaxLength(255);

            this.Property(t => t.Summary)
                .IsRequired()
                .HasMaxLength(4000);

            this.Property(t => t.Text)
                .IsRequired();

            // Table & Column Mappings
            this.ToTable("NewsItem");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.Title).HasColumnName("Title");
            this.Property(t => t.Summary).HasColumnName("Summary");
            this.Property(t => t.Text).HasColumnName("Text");
            this.Property(t => t.CreationDate).HasColumnName("CreationDate");
            this.Property(t => t.ModificationData).HasColumnName("ModificationData");
            this.Property(t => t.PersonId).HasColumnName("PersonId");

            // Relationships
            this.HasRequired(t => t.Person)
                .WithMany(t => t.NewsItems)
                .HasForeignKey(d => d.PersonId);

        }
    }
}
